{template "header.html"}
<script type="text/javascript">
$(function() {
	SwapTab(0);
	$(".table_form tr>th").attr("width", 150);
	$(".dr_000 tr").last().addClass("dr_border_none");
    // 错误提示
	{if $error}
	art.dialog.tips('<font color=red>{$error.msg}</font>', 3);
	{/if}
    // 结果显示
	{if $result}
	art.dialog.tips('{$result}', 3, 1);
	{/if}
    // 生成静态文件
	{if $create}
	$.post('{$create}&rand='+Math.random(),{}, function(){});
	$.post('{SITE_URL}{APP_DIR}/index.php?c=home&m=create_list_html&id={$catid}&rand='+Math.random(),{}, function(){});
	{/if}
    //每隔5秒保存表单数据
    {if !$data.id && !$did}
    setInterval("dr_save_add_data()", 5000);
    {/if}
    // 加载草稿
    $("#dr_cgbox").mouseover(function(){
        $(".dr_cgbox").show();
    }).mouseout(function(){
        $(".dr_cgbox").hide();
    });
    // 删除草稿数据
    $(".dr_cgbox_delete").click(function(){
        var did = $(this).attr("did");
        var num = parseInt($("#dr_cg_nums").html());
        $.ajax({
            type: "POST",
            dataType:"json",
            url: memberpath+'index.php?c=api&m=ajax_delete_draft&sid={SITE_ID}&dir={APP_DIR}&did='+did,
            success: function(data) {
                if (data == did) {
                    $("#dr_cgbox_"+did).remove();
                    $("#dr_cg_nums").html(num - 1);
                } else {
                    dr_tips(data);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) { }
        });
    });
    $(".dr_cgbox_select").click(function(){
       var did = $(this).attr("did");
       window.location.href = '{$draft_url}&did='+did;
    });
    // 自动保存草稿
    {if $did}
    setInterval("dr_save_draft_data()", 5000);
    {/if}
	//
	{if $data.syncatid}
		$("#dr_syncat_num").html("{php echo substr_count($data.syncatid, '|')}");
		$("#dr_syncat_text").show();
	{/if}
});
// 修改栏目时的页面跳转
function show_category_field(catid) {
    {if $is_category_field}
    window.location.href = '{dr_url(APP_DIR."/home/".$ci->router->method, array("id"=>$data.id))}&catid='+catid;
    {/if}
}
// 动态保存草稿数据
function dr_save_draft_data() {
    var catid = $('#dr_catid').val();
    $.ajax({
        type: "POST",
        dataType:"json",
        url: memberpath+'index.php?c=api&m=ajax_save_draft&sid={SITE_ID}&dir={APP_DIR}&did={$did}&catid='+catid,
        data: $("#myform").serialize(),
        success: function(data) { },
        error: function(HttpRequest, ajaxOptions, thrownError) { }
    });
}
// 动态保存表单数据
function dr_save_add_data() {
    $.ajax({
        type: "POST",
        dataType:"json",
        url: memberpath+'index.php?c=api&m=ajax_save_add&dir={APP_DIR}',
        data: $("#myform").serialize(),
        success: function(data) { },
        error: function(HttpRequest, ajaxOptions, thrownError) { }
    });
}
// 同步到其他栏目选择
function dr_syncat() {
    var url = "{dr_url(APP_DIR.'/home/syncat_ajax')}&ids="+$("#dr_syncatid").val();
    art.dialog.open(url, { title: '{lang("cat-100")}',
        ok: function () {
            var iframe = this.iframe.contentWindow;
            if (!iframe.document.body) {
                alert('iframe loading')
                return false;
            };
            var c = 0;
            var v = '';
            iframe.$("input[type='hidden']").each(function (i) {
                v+= $(this).val()+'|';
                c++;
            });
            $("#dr_syncatid").val(v);
            $("#dr_syncat_num").html(c);
            $("#dr_syncat_text").show();
            return true;
        },
        cancel: true
    });
}
</script>
<form action="" method="post" name="myform" id="myform">
<input name="page" id="page" type="hidden" value="{$page}" />
<input name="action" id="dr_action" type="hidden" value="back" />
<input name="dr_id" id="dr_id" type="hidden" value="{$data.id}" />
<input name="dr_module" id="dr_module" type="hidden" value="{APP_DIR}" />
<div class="subnav">
	<div class="content-menu ib-a blue line-x">
		{$menu}
	</div>
	<div class="bk10"></div>
    <div class="table-list col-tab">
        {if $draft_list}
        <ul class="tabBut2 cu-li">
            <li class="cg li" id="dr_cgbox">
                {lang('html-790')}（<span id="dr_cg_nums">{count($draft_list)}</span>）
                <fieldset class="dr_cgbox" style="display:none">
                    <div class="picList">
                        <ul class="cg_items" style="max-height: 400px;overflow-y: auto;">
                            {loop $draft_list $t}
                            <li id="dr_cgbox_{$t.id}">
                                <a href="javascript:;" class="dr_cgbox_delete" did="{$t.id}" title="{lang('del')}"><img align="absmiddle" src="{SITE_URL}dayrui/statics/images/b_drop.png"></a>
                                <span>{dr_date($t.inputtime)}</span>
                                <a href="javascript:;" class="dr_cgbox_select" did="{$t.id}">{$t.title}</a>
                            </li>
                            {/loop}
                        </ul>
                    </div>
                </fieldset>
            </li>
        </ul>
        {/if}

		<div class="bk10"></div>
        <div class="dr_table">
			<fieldset>
			<legend>{lang('mod-600')}</legend>
			<table width="100%" class="table_form dr_000">
			<tr>
				<th width="150"><font color="red">*</font>&nbsp;{lang('cat-00')}： </th>
				<td>
					{$select}
					{if $ci->get_cache('module-'.SITE_ID.'-'.APP_DIR, 'setting', 'syncat')}
					&nbsp;&nbsp;
					{if !$data.id}
						<a href="javascript:;" onclick="dr_syncat()">[{lang('cat-100')}]</a>
						<input name="syncatid" id="dr_syncatid" type="hidden" value="{$data.syncatid}" />
					&nbsp;&nbsp;<span id="dr_syncat_text" style="display: none;color: blue;">{lang('cat-103')}<b id="dr_syncat_num">0</b></span>
					{else if $data.link_id != 0}
					{lang('cat-104')}
					{/if}
					{/if}
				</td>
			</tr>
			{$myfield}
			</table>
			</fieldset>
            {if $flag || (!$data.id && $ci->get_cache('module-'.SITE_ID.'-'.APP_DIR, 'setting', 'syn2'))}
			<div class="bk10"></div>
			<fieldset>
			<legend>{lang('357')}</legend>
			<table width="100%" class="table_form">
			{if $flag}
			<tr>
				<th>{lang('html-174')}： </th>
				<td>
				{loop $flag $i $t}
				{if $t.name}<input name="flag[]" type="checkbox" {if @in_array($i, $myflag)}checked="checked" {/if}value="{$i}" />&nbsp;<label>{$t.name}</label>&nbsp;&nbsp;&nbsp;{/if}
				{/loop}
				</td>
			</tr>
			{/if}
			{if !$data.id && $ci->get_cache('module-'.SITE_ID.'-'.APP_DIR, 'setting', 'syn2')}
			<tr>
				<th>{lang('m-113')}： </th>
				<td>
				<input name="qq_share" type="checkbox" checked="checked" value="1" />
				<label>腾讯微博</label>
				{if !$member.oauth.qq}<label style="color:#FF0000">（请进入会员中心-账户-快捷登录，绑定QQ账户）</label>{/if}
				&nbsp;&nbsp;
				<input name="sina_share" type="checkbox" checked="checked" value="1" />
				<label>新浪微博</label>
				{if !$member.oauth.sina}<label style="color:#FF0000">（请进入会员中心-账户-快捷登录，绑定新浪账户）</label>{/if}
				</td>
			</tr>
			{/if}
			</table>
			</fieldset>
            {/if}
        </div>
    </div>
</div>
<div class="fixed-bottom">
    <div class="fixed-but text-c">
        <div class="button"><input value="{lang('html-789')}" type="submit" name="submit" class="cu" onclick="$('#dr_action').val('draft')" style="width:100px;" /></div>
        <div class="button"><input value="{lang('html-362')}" type="submit" name="submit" class="cu" onclick="$('#dr_action').val('back')" style="width:100px;" /></div>
        {if !$data.id}
        <div class="button"><input value="{lang('html-363')}" type="submit" name="submit" class="cu" onclick="$('#dr_action').val('continue')" style="width:100px;" /></div>
        {/if}
    </div>
</div>
</form>
{template footer.html}